'''对该ip进行decrease操作'''
import sys
import os
# os.path.dirname(path)——返回文件路径
# os.path.abspath()——获得绝对路径。
curPath = os.path.abspath(os.path.dirname(__file__))
# os.path.split(path)——返回路径的目录和文件名，即将目录和文件名分开，而不是一个整体。此处只是把前后两部分分开而已。就是找最后一个’/’
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath) #添加retry文件夹的路径，这样才能找到ProxyPool(不需要添加其子文件夹——即retry/retry，但是感觉添加了也能找到)

from proxypool.schemas.proxy import Proxy
from proxypool.storages.redis import RedisClient
from proxypool.utils.proxy import convert_proxy_or_proxies

redis = RedisClient()

def delete_proxy(proxy: Proxy):
    if proxy:
        # delete proxy from proxies pool
        # print("代理" + proxy + "就8行！！！(执行减分操作)")
        print(f"代理 {proxy.string()} 就8行！！！(执行减分操作)")  # 03-07修改
        redis.decrease(convert_proxy_or_proxies(proxy))
        print("-" * 100)

if __name__ == '__main__':
    proxy_1 = "211.159.219.225:8118"
    proxy_1 = proxy_1.strip()
    host, port = proxy_1.split(':')
    proxy_1 = Proxy(host=host, port=int(port))
    proxy_2 = b"123.169.166.96:9999"
    delete_proxy(convert_proxy_or_proxies(proxy_1))
    # delete_proxy(convert_proxy_or_proxies(proxy_2))

